<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="JSON," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="JSON (JavaScript Object Notion, JavaScript &amp;#x5BF9;&amp;#x8C61;&amp;#x8868;&amp;#x793A;&amp;#x6CD5;)
JSON &amp;#x662F; JavaScript &amp;#x7684;&amp;#x4E00;&amp;#x4E2A;&amp;#x4E25;&amp;#x683C;&amp;#x7684;&amp;#x5B50;&amp;#x96C6;&amp;#xFF0C;&amp;#x5B83;&amp;#x662F;&amp;#">
<meta property="og:type" content="article">
<meta property="og:title" content="JSON 数据">
<meta property="og:url" content="https://hongqinma.github.io/2014/12/17/22-JSON/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="JSON (JavaScript Object Notion, JavaScript &amp;#x5BF9;&amp;#x8C61;&amp;#x8868;&amp;#x793A;&amp;#x6CD5;)
JSON &amp;#x662F; JavaScript &amp;#x7684;&amp;#x4E00;&amp;#x4E2A;&amp;#x4E25;&amp;#x683C;&amp;#x7684;&amp;#x5B50;&amp;#x96C6;&amp;#xFF0C;&amp;#x5B83;&amp;#x662F;&amp;#">
<meta property="og:updated_time" content="2016-11-29T10:43:55.112Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JSON 数据">
<meta name="twitter:description" content="JSON (JavaScript Object Notion, JavaScript &amp;#x5BF9;&amp;#x8C61;&amp;#x8868;&amp;#x793A;&amp;#x6CD5;)
JSON &amp;#x662F; JavaScript &amp;#x7684;&amp;#x4E00;&amp;#x4E2A;&amp;#x4E25;&amp;#x683C;&amp;#x7684;&amp;#x5B50;&amp;#x96C6;&amp;#xFF0C;&amp;#x5B83;&amp;#x662F;&amp;#">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2014/12/17/22-JSON/"/>


  <title> JSON 数据 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                JSON 数据
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2014-12-17T21:25:32+08:00" content="2014-12-17">
              2014-12-17
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2014/12/17/22-JSON/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2014/12/17/22-JSON/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
            <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>JSON (JavaScript Object Notion, JavaScript &#x5BF9;&#x8C61;&#x8868;&#x793A;&#x6CD5;)</p>
<p>JSON &#x662F; JavaScript &#x7684;&#x4E00;&#x4E2A;&#x4E25;&#x683C;&#x7684;&#x5B50;&#x96C6;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x79CD;&#x6570;&#x636E;&#x683C;&#x5F0F;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4E00;&#x79CD;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x3002;</p>
<h2 id="&#x8BED;&#x6CD5;"><a href="#&#x8BED;&#x6CD5;" class="headerlink" title="&#x8BED;&#x6CD5;"></a>&#x8BED;&#x6CD5;</h2><p>JSON &#x8BED;&#x6CD5;&#x53EF;&#x4EE5;&#x8868;&#x793A;&#x4EE5;&#x4E0B;&#x4E09;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF1A;</p>
<p><strong>&#x7B80;&#x5355;&#x503C;</strong>&#xFF1A;&#x4F7F;&#x7528; JavaScript &#x76F8;&#x540C;&#x7684;&#x8BED;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5728; JSON &#x4E2D;&#x8868;&#x793A;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x6570;&#x503C;&#x3001;&#x5E03;&#x5C14;&#x503C;&#x548C; null&#xFF0C;&#x4E0D;&#x652F;&#x6301; undefined&#x3002;</p>
<p><strong>&#x5BF9;&#x8C61;</strong>&#xFF1A;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x4E00;&#x79CD;&#x590D;&#x6742;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x8868;&#x793A;&#x7684;&#x662F;&#x4E00;&#x7EC4;&#x65E0;&#x5E8F;&#x7684;&#x952E;&#x503C;&#x5BF9;&#x7684;&#x503C;&#xFF0C;&#x6BCF;&#x4E2A;&#x952E;&#x503C;&#x5BF9;&#x7684;&#x503C;&#x53EF;&#x4EE5;&#x662F;&#x7B80;&#x5355;&#x7C7B;&#x578B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x590D;&#x6742;&#x7C7B;&#x578B;&#x3002;</p>
<p><strong>&#x6570;&#x7EC4;</strong>&#xFF1A;&#x6570;&#x7EC4;&#x4E5F;&#x662F;&#x4E00;&#x79CD;&#x590D;&#x6742;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x8868;&#x793A;&#x4E00;&#x7EC4;&#x6709;&#x5E8F;&#x7684;&#x503C;&#x7684;&#x5217;&#x8868;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6570;&#x503C;&#x7D22;&#x5F15;&#x6765;&#x8BBF;&#x95EE;&#x5176;&#x4E2D;&#x7684;&#x503C;&#x3002;&#x6570;&#x7EC4;&#x7684;&#x503C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x610F;&#x7C7B;&#x578B;-&#x7B80;&#x5355;&#x503C;&#x3001;&#x5BF9;&#x8C61;&#x6216;&#x6570;&#x7EC4;&#x3002;</p>
<p>JSON &#x5BF9;&#x8C61;&#x4E0D;&#x652F;&#x6301;&#x53D8;&#x91CF;&#x3001;&#x51FD;&#x6570;&#x6216;&#x5BF9;&#x8C61;&#x5B9E;&#x4F8B;&#xFF0C;&#x5B83;&#x5C31;&#x662F;&#x4E00;&#x79CD;&#x8868;&#x793A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x5316;&#x7684;&#x6570;&#x636E;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x867D;&#x7136;&#x4E0E; JavaScript &#x4E2D;&#x8868;&#x793A;&#x6570;&#x636E;&#x7684;&#x67D0;&#x4E9B;&#x8BED;&#x6CD5;&#x76F8;&#x540C;&#xFF0C;&#x4F46;&#x5B83;&#x5E76;&#x4E0D;&#x5C40;&#x9650;&#x4E8E; JavaScript &#x7684;&#x8303;&#x7574;</p>
<h3 id="&#x7B80;&#x5355;&#x503C;"><a href="#&#x7B80;&#x5355;&#x503C;" class="headerlink" title="&#x7B80;&#x5355;&#x503C;"></a>&#x7B80;&#x5355;&#x503C;</h3><ul>
<li>5 &#x8FD9;&#x662F; JSON &#x8868;&#x793A;&#x6570;&#x503C; 5 &#x7684;&#x65B9;&#x5F0F;&#x3002;</li>
<li>&#x201C;str&#x201D; &#x8FD9;&#x662F; JSON &#x8868;&#x793A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x65B9;&#x5F0F;&#x3002;</li>
</ul>
<h3 id="&#x5BF9;&#x8C61;"><a href="#&#x5BF9;&#x8C61;" class="headerlink" title="&#x5BF9;&#x8C61;"></a>&#x5BF9;&#x8C61;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> person = {</div><div class="line">  <span class="attr">name</span>: <span class="string">&quot;Hiraku&quot;</span>,</div><div class="line">  <span class="attr">age</span>: <span class="number">25</span></div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x7528; JSON &#x8868;&#x793A;&#x4E3A;&#xFF1A;</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line">  <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;Hiraku&quot;</span>,</div><div class="line">  <span class="attr">&quot;age&quot;</span>: <span class="number">25</span></div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x53C8;&#x5982;&#xFF1A;</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line">  <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;Hiraku&quot;</span>,</div><div class="line">  <span class="attr">&quot;age&quot;</span>: <span class="number">25</span>,</div><div class="line">  <span class="attr">&quot;school&quot;</span>: [</div><div class="line">    {</div><div class="line">      <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;Shantou University&quot;</span>,</div><div class="line">      <span class="attr">&quot;location&quot;</span>: <span class="string">&quot;Guangdong&quot;</span></div><div class="line">    },</div><div class="line">    {</div><div class="line">      <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;Technology of LanZhou University&quot;</span>,</div><div class="line">      <span class="attr">&quot;location&quot;</span>: <span class="string">&quot;Gansu&quot;</span></div><div class="line">    }</div><div class="line">  ]</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="&#x6570;&#x7EC4;"><a href="#&#x6570;&#x7EC4;" class="headerlink" title="&#x6570;&#x7EC4;"></a>&#x6570;&#x7EC4;</h3><p>JSON &#x4E2D;&#x7684;&#x590D;&#x6742;&#x6570;&#x636E;&#x662F;&#x6570;&#x7EC4;&#x3002; JSON &#x6570;&#x7EC4;&#x91C7;&#x7528;&#x7684;&#x5C31;&#x662F; JavaScript &#x4E2D;&#x7684;&#x6570;&#x5B57;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x5F62;&#x5F0F;&#x3002;</p>
<p>&#x5982;&#xFF1A;</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[25, &quot;Hiraku&quot;, 0];</div></pre></td></tr></table></figure>
<p>JSON &#x6570;&#x7EC4;&#x4E5F;&#x6CA1;&#x6709;&#x53D8;&#x91CF;&#x548C;&#x5206;&#x53F7;&#x3002;&#x628A;&#x6570;&#x7EC4;&#x548C;&#x5BF9;&#x8C61;&#x7ED3;&#x5408;&#x8D77;&#x6765;&#xFF0C;&#x53EF;&#x4EE5;&#x6784;&#x6210;&#x66F4;&#x590D;&#x6742;&#x7684;&#x6570;&#x636E;&#x96C6;&#x5408;&#x3002;</p>
<p>&#x5982;&#xFF1A;</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[</div><div class="line">  {</div><div class="line">    <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">    <span class="attr">&quot;authors&quot;</span>: [</div><div class="line">      <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">      <span class="string">&quot;Herscharl&quot;</span></div><div class="line">    ],</div><div class="line">    <span class="attr">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">    <span class="attr">&quot;year&quot;</span>: <span class="number">2013</span></div><div class="line">  },</div><div class="line">  {</div><div class="line">    <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;HTML&quot;</span>,</div><div class="line">    <span class="attr">&quot;authors&quot;</span>: [</div><div class="line">      <span class="string">&quot;HuangShan&quot;</span>, </div><div class="line">      <span class="string">&quot;Jack&quot;</span></div><div class="line">    ],</div><div class="line">    <span class="attr">&quot;edition&quot;</span>: <span class="number">1</span>,</div><div class="line">    <span class="attr">&quot;year&quot;</span>: <span class="number">2012</span></div><div class="line">  },</div><div class="line">  {</div><div class="line">    <span class="attr">&quot;title&quot;</span>: <span class="string">&quot;Java&quot;</span>,</div><div class="line">    <span class="attr">&quot;authors&quot;</span>: [</div><div class="line">      <span class="string">&quot;TangTang&quot;</span></div><div class="line">    ],</div><div class="line">    <span class="attr">&quot;edition&quot;</span>: <span class="number">2</span>,</div><div class="line">    <span class="attr">&quot;year&quot;</span>: <span class="number">2015</span></div><div class="line">  },</div><div class="line">]</div></pre></td></tr></table></figure>
<h2 id="JSON-&#x89E3;&#x6790;&#x548C;&#x5E8F;&#x5217;&#x5316;"><a href="#JSON-&#x89E3;&#x6790;&#x548C;&#x5E8F;&#x5217;&#x5316;" class="headerlink" title="JSON &#x89E3;&#x6790;&#x548C;&#x5E8F;&#x5217;&#x5316;"></a>JSON &#x89E3;&#x6790;&#x548C;&#x5E8F;&#x5217;&#x5316;</h2><p>JSON &#x6570;&#x636E;&#x53EF;&#x4EE5;&#x89E3;&#x6790;&#x4E3A; JavaScript &#x5BF9;&#x8C61;&#x4F18;&#x52BF;&#x53CA;&#x5176;&#x660E;&#x663E;&#x3002;</p>
<h3 id="JSON-&#x5BF9;&#x8C61;"><a href="#JSON-&#x5BF9;&#x8C61;" class="headerlink" title="JSON &#x5BF9;&#x8C61;"></a>JSON &#x5BF9;&#x8C61;</h3><p>eval() &#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x89E3;&#x6790;&#x3001;&#x89E3;&#x91CA;&#x5E76;&#x8FD4;&#x56DE; JavaScript &#x5BF9;&#x8C61;&#x548C;&#x6570;&#x7EC4;&#x3002;</p>
<p>&#x4E24;&#x4E2A;&#x91CD;&#x8981;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>JSON.stringify()</code><ul>
<li><em>&#x628A; JavaScript &#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x4E3A; JSON &#x5B57;&#x7B26;&#x4E32;</em></li>
</ul>
</li>
<li><code>JSON.parse()</code><ul>
<li><em>&#x628A; JSON &#x5B57;&#x7B26;&#x4E32;&#x89E3;&#x6790;&#x4E3A;&#x539F;&#x751F;&#x7684; JavaScript &#x503C;</em></li>
</ul>
</li>
</ul>
<h3 id="JSON-stringify-&#x8BE6;&#x89E3;"><a href="#JSON-stringify-&#x8BE6;&#x89E3;" class="headerlink" title="JSON.stringify() &#x8BE6;&#x89E3;"></a>JSON.stringify() &#x8BE6;&#x89E3;</h3><p>&#x51FA;&#x6765;&#x8981;&#x5E8F;&#x5217;&#x5316;&#x7684; JavaScript &#x5BF9;&#x8C61;&#x5916;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x53E6;&#x5916;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x7528;&#x4E8E;&#x6307;&#x5B9A;&#x4EE5;&#x4E0D;&#x540C;&#x65B9;&#x5F0F;&#x5E8F;&#x5217;&#x5316; JavaScript &#x5BF9;&#x8C61;&#x3002;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x9009;&#x62E9;&#xFF0C;&#x8868;&#x793A;&#x662F;&#x5426;&#x5728; JSON &#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x4FDD;&#x7559;&#x7F29;&#x8FDB;&#x3002;</p>
<p>&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x6570;&#x7EC4;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> book = {</div><div class="line">  <span class="string">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">  <span class="string">&quot;authors&quot;</span>: [</div><div class="line">    <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">    <span class="string">&quot;Herscharl&quot;</span></div><div class="line">  ],</div><div class="line">  <span class="string">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">  <span class="string">&quot;year&quot;</span>: <span class="number">2013</span></div><div class="line">}</div><div class="line"><span class="keyword">var</span> jsonText = <span class="built_in">JSON</span>.stringify(book, [<span class="string">&quot;title&quot;</span>, <span class="string">&quot;edition&quot;</span>]);</div><div class="line"><span class="built_in">console</span>.log(jsonText); <span class="comment">// {&quot;title&quot;:&quot;JavaScript&quot;,&quot;edition&quot;:3}</span></div></pre></td></tr></table></figure>
<p>&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x51FD;&#x6570;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> book = {</div><div class="line">  <span class="string">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">  <span class="string">&quot;authors&quot;</span>: [</div><div class="line">    <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">    <span class="string">&quot;Herscharl&quot;</span></div><div class="line">  ],</div><div class="line">  <span class="string">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">  <span class="string">&quot;year&quot;</span>: <span class="number">2013</span></div><div class="line">}</div><div class="line"><span class="keyword">var</span> jsonText = <span class="built_in">JSON</span>.stringify(book, <span class="function"><span class="keyword">function</span>(<span class="params">key, value</span>) </span>{</div><div class="line">  <span class="keyword">switch</span>(key){</div><div class="line">    <span class="keyword">case</span> <span class="string">&quot;authors&quot;</span>:</div><div class="line">      <span class="keyword">return</span> value.join(<span class="string">&quot;,&quot;</span>);</div><div class="line">    <span class="keyword">case</span> <span class="string">&quot;year&quot;</span>:</div><div class="line">      <span class="keyword">return</span> <span class="string">&quot;year&quot;</span>;</div><div class="line">    <span class="keyword">case</span> <span class="string">&quot;edition&quot;</span>:</div><div class="line">      <span class="keyword">return</span> <span class="literal">undefined</span>;</div><div class="line">    <span class="keyword">default</span> :</div><div class="line">      <span class="keyword">return</span> value;</div><div class="line">  } </div><div class="line">});</div><div class="line"><span class="built_in">console</span>.log(jsonText); <span class="comment">// {&quot;title&quot;:&quot;JavaScript&quot;,&quot;authors&quot;:&quot;Hirkau,Herscharl&quot;,&quot;year&quot;:&quot;year&quot;}</span></div></pre></td></tr></table></figure>
<p>&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x63A7;&#x5236;&#x7ED3;&#x679C;&#x4E2D;&#x7684;&#x7F29;&#x8FDB;&#x548C;&#x7A7A;&#x767D;&#x7B26;&#xFF1A;&#x6700;&#x5927;&#x7F29;&#x8FDB;&#x7A7A;&#x683C;&#x4E3A; 10 &#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> book = {</div><div class="line">  <span class="string">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">  <span class="string">&quot;authors&quot;</span>: [</div><div class="line">    <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">    <span class="string">&quot;Herscharl&quot;</span></div><div class="line">  ],</div><div class="line">  <span class="string">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">  <span class="string">&quot;year&quot;</span>: <span class="number">2013</span></div><div class="line">}</div><div class="line"><span class="keyword">var</span> jsonText = <span class="built_in">JSON</span>.stringify(book, <span class="literal">null</span>, <span class="number">4</span>);</div><div class="line"><span class="built_in">console</span>.log(jsonText);</div></pre></td></tr></table></figure>
<p>&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x662F;&#xFF1A;</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line">    &quot;title&quot;: &quot;JavaScript&quot;,</div><div class="line">    &quot;authors&quot;: [</div><div class="line">        &quot;Hirkau&quot;,</div><div class="line">        &quot;Herscharl&quot;</div><div class="line">    ],</div><div class="line">    &quot;edition&quot;: 3,</div><div class="line">    &quot;year&quot;: 2013</div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x5B57;&#x7B26;&#x65F6;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> book = {</div><div class="line">  <span class="string">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">  <span class="string">&quot;authors&quot;</span>: [</div><div class="line">    <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">    <span class="string">&quot;Herscharl&quot;</span></div><div class="line">  ],</div><div class="line">  <span class="string">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">  <span class="string">&quot;year&quot;</span>: <span class="number">2013</span></div><div class="line">}</div><div class="line"><span class="keyword">var</span> jsonText = <span class="built_in">JSON</span>.stringify(book, <span class="literal">null</span>, <span class="string">&quot; - -&quot;</span>);</div><div class="line"><span class="built_in">console</span>.log(jsonText);</div></pre></td></tr></table></figure>
<p>&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#xFF1A;</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line"> - -&quot;title&quot;: &quot;JavaScript&quot;,</div><div class="line"> - -&quot;authors&quot;: [</div><div class="line"> - - - -&quot;Hirkau&quot;,</div><div class="line"> - - - -&quot;Herscharl&quot;</div><div class="line"> - -],</div><div class="line"> - -&quot;edition&quot;: 3,</div><div class="line"> - -&quot;year&quot;: 2013</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="toJSON-&#x65B9;&#x6CD5;"><a href="#toJSON-&#x65B9;&#x6CD5;" class="headerlink" title="toJSON() &#x65B9;&#x6CD5;"></a>toJSON() &#x65B9;&#x6CD5;</h3><p>&#x5728; JSON.stringify() &#x65B9;&#x6CD5;&#x4E0D;&#x80FD;&#x6EE1;&#x8DB3;&#x67D0;&#x4E9B;&#x72EC;&#x4EAB;&#x8FDB;&#x884C;&#x81EA;&#x5B9A;&#x4E49;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x9700;&#x6C42;&#x3002;&#x53EF;&#x4EE5;&#x7ED9;&#x5BF9;&#x8C61;&#x5B9A;&#x4E49; toJSON() &#x65B9;&#x6CD5;&#xFF0C;&#x8FD4;&#x56DE;&#x81EA;&#x8EAB;&#x7684; JSON &#x6570;&#x636E;&#x683C;&#x5F0F;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> book = {</div><div class="line">  <span class="string">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">  <span class="string">&quot;authors&quot;</span>: [</div><div class="line">    <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">    <span class="string">&quot;Herscharl&quot;</span></div><div class="line">  ],</div><div class="line">  <span class="string">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">  <span class="string">&quot;year&quot;</span>: <span class="number">2013</span>,</div><div class="line">    <span class="attr">toJSON</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</div><div class="line">      <span class="keyword">return</span> <span class="keyword">this</span>.title;</div><div class="line">    }</div><div class="line">}</div><div class="line"><span class="keyword">var</span> jsonText = <span class="built_in">JSON</span>.stringify(book);</div><div class="line"><span class="built_in">console</span>.log(jsonText); <span class="comment">// &quot;JavaScript&quot;</span></div></pre></td></tr></table></figure>
<p><strong>&#x5E8F;&#x5217;&#x5316;&#x7684;&#x987A;&#x5E8F;&#xFF1A;</strong></p>
<p>(1) &#x5982;&#x679C;&#x5B58;&#x5728; toJSON() &#x65B9;&#x6CD5;&#x800C;&#x4E14;&#x80FD;&#x901A;&#x8FC7;&#x5B83;&#x53D6;&#x5F97;&#x6709;&#x6548;&#x7684;&#x503C;&#xFF0C;&#x5219;&#x8C03;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;&#xFF0C;&#x5426;&#x5219;&#xFF0C;&#x8FD4;&#x56DE;&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#xFF1B;</p>
<p>(2) &#x5982;&#x679C;&#x63D0;&#x4F9B;&#x4E86;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5E94;&#x7528;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x4F20;&#x5165;&#x51FD;&#x6570;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x503C;&#x662F;&#x7B2C; (1) &#x6B65;&#x8FD4;&#x56DE;&#x7684;&#x503C;&#xFF1B;</p>
<p>(3) &#x5BF9;&#x7B2C; (2) &#x6B65;&#x8FD4;&#x56DE;&#x7684;&#x6BCF;&#x4E2A;&#x503C;&#x8FDB;&#x884C;&#x76F8;&#x5E94;&#x7684;&#x5E8F;&#x5217;&#x5316;&#xFF1B;</p>
<p>(4) &#x5982;&#x679C;&#x63D0;&#x4F9B;&#x4E86;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x6267;&#x884C;&#x76F8;&#x5E94;&#x7684;&#x5E8F;&#x5217;&#x5316;&#x3002;</p>
<h2 id="&#x89E3;&#x6790;&#x9009;&#x9879;"><a href="#&#x89E3;&#x6790;&#x9009;&#x9879;" class="headerlink" title="&#x89E3;&#x6790;&#x9009;&#x9879;"></a>&#x89E3;&#x6790;&#x9009;&#x9879;</h2><p>JSON.parse() &#x65B9;&#x6CD5;&#x4E5F;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x53E6;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8BE5;&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x5C06;&#x5728;&#x6BCF;&#x4E2A;&#x952E;&#x503C;&#x5BF9;&#x4E0A;&#x8C03;&#x7528;&#x3002;&#x4E3A;&#x4E86;&#x533A;&#x522B; JSON.stringify() &#x63A5;&#x6536;&#x7684;&#x66FF;&#x6362;(&#x8FC7;&#x6EE4;)&#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x88AB;&#x79F0;&#x4E3A;&#x8FD8;&#x539F;&#x51FD;&#x6570;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x8FD9;&#x4E24;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x7B7E;&#x540D;&#x662F;&#x76F8;&#x540C;&#x7684;-&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E00;&#x4E2A;&#x952E;&#x548C;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x800C;&#x4E14;&#x90FD;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x503C;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> book = {</div><div class="line">  <span class="string">&quot;title&quot;</span>: <span class="string">&quot;JavaScript&quot;</span>,</div><div class="line">  <span class="string">&quot;authors&quot;</span>: [</div><div class="line">    <span class="string">&quot;Hirkau&quot;</span>, </div><div class="line">    <span class="string">&quot;Herscharl&quot;</span></div><div class="line">  ],</div><div class="line">  <span class="string">&quot;edition&quot;</span>: <span class="number">3</span>,</div><div class="line">  <span class="string">&quot;year&quot;</span>: <span class="number">2013</span>,</div><div class="line">  <span class="attr">releaseDate</span>: <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="number">2011</span>, <span class="number">11</span>, <span class="number">1</span>)</div><div class="line">}</div><div class="line"><span class="keyword">var</span> jsonText = <span class="built_in">JSON</span>.stringify(book);</div><div class="line"><span class="keyword">var</span> bookCopy = <span class="built_in">JSON</span>.parse(jsonText, <span class="function"><span class="keyword">function</span>(<span class="params">key, value</span>) </span>{</div><div class="line">  <span class="keyword">if</span> (key == <span class="string">&quot;releaseDate&quot;</span>) {</div><div class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Date</span>(value);</div><div class="line">  } <span class="keyword">else</span> {</div><div class="line">    <span class="keyword">return</span> value;</div><div class="line">  }</div><div class="line">});</div><div class="line"><span class="built_in">console</span>.log(bookCopy.releaseDate.getFullYear()); <span class="comment">// 2011</span></div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>感谢您的支持！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>打 赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/JSON/" rel="tag">#JSON</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2014/12/05/21-jQuery/" rel="next" title="jQuery">
                <i class="fa fa-chevron-left"></i> jQuery
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/01/15/23-Ajax/" rel="prev" title="Ajax">
                Ajax <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2014/12/17/22-JSON/"
     data-title="JSON 数据"
     data-content=""
     data-url="https://hongqinma.github.io/2014/12/17/22-JSON/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2014/12/17/22-JSON/"
           data-title="JSON 数据" data-url="https://hongqinma.github.io/2014/12/17/22-JSON/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">68</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">57</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#语法"><span class="nav-number">1.</span> <span class="nav-text">语法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#简单值"><span class="nav-number">1.1.</span> <span class="nav-text">简单值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#对象"><span class="nav-number">1.2.</span> <span class="nav-text">对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组"><span class="nav-number">1.3.</span> <span class="nav-text">数组</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-解析和序列化"><span class="nav-number">2.</span> <span class="nav-text">JSON 解析和序列化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#JSON-对象"><span class="nav-number">2.1.</span> <span class="nav-text">JSON 对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JSON-stringify-详解"><span class="nav-number">2.2.</span> <span class="nav-text">JSON.stringify() 详解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#toJSON-方法"><span class="nav-number">2.3.</span> <span class="nav-text">toJSON() 方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解析选项"><span class="nav-number">3.</span> <span class="nav-text">解析选项</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
